package com.mathdroid.model.items;

import java.util.HashMap;

import com.mathdroid.model.Stats;
import com.mathdroid.model.enums.EItemSlot;
import com.mathdroid.model.enums.EItemStat;

/**
 * This is an item template. The items are unique by slot.
 */
public final class EquipedItems extends HashMap<EItemSlot, Item> {

	/**
	 * Generated UID.
	 */
	private static final long serialVersionUID = -6447746503484954198L;
	
	/**
	 * The name of the item template / item outfit.
	 */
	private String name = "Unnamed";

	/**
	 * Set the name of this template.
	 * @param n Name.
	 */
	public void setName(final String n) {
		this.name = n;
	}
	
	@Override
	public String toString() {
		return this.name;
	}
	
	/**
	 * This method accumulates all the stats of this item list.
	 * @param estat The stat to accumulate.
	 * @return Total value of this stat.
	 */
	public int getTotalStats(final EItemStat estat) {
		int sum = 0;
		
		for (Item i : this.values()) {
			sum += i.getTotalStat(estat);
		}
		
		return sum;
	}

	/**
	 * Get a new Stats object that contains <b>all</b> item stats.
	 * @return Total Stats object.
	 */
	public Stats getTotalStats() {
		final Stats stats = new Stats();
		
		for (EItemStat s : EItemStat.getAllStats()) {
			stats.put(s, this.getTotalStats(s));
		}
		
		return stats;
	}
}
